//
//  MainProductCollectionCell.m
//  Ufan
//
//  Created by lori on 15/12/23.
//  Copyright © 2015年 yangqingluo. All rights reserved.
//

#import "MainProductCollectionCell.h"
#import "UIImageView+EMWebCache.h"

@implementation MainProductCollectionCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.contentView.backgroundColor = [UIColor clearColor];
        self.contentView.layer.borderWidth = 1;
        self.contentView.layer.borderColor = RGBA(170, 170, 170, 0.4).CGColor;
        
//        self.baseView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 0.9 * self.contentView.width, 0.9 * self.contentView.height)];
//        self.baseView.backgroundColor = RGBA(255, 255, 255, 0.1);
//        self.baseView.center = CGPointMake(0.5 * self.contentView.width, 0.5 * self.contentView.height);
//        [self.contentView addSubview:self.baseView];
//        self.baseView.layer.cornerRadius = 5.0;
//        self.baseView.layer.masksToBounds = YES;
//        self.baseView.highlightedImage = [UIImage imageNamed:@"collection_cell_selected"];
        
        self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.contentView.width, self.contentView.width * 3.0 / 4.0)];
        self.imageView.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.imageView];
        
        self.textLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, self.imageView.bottom, self.contentView.width - 10, 40)];
        self.textLabel.textColor = [UIColor blackColor];
        self.textLabel.numberOfLines = 0;
        self.textLabel.font = [UIFont systemFontOfSize:16.0];
        self.textLabel.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:self.textLabel];
        
        self.detailTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, self.textLabel.bottom, self.contentView.width - 10, 20)];
        self.detailTextLabel.textColor = [UIColor orangeColor];
        self.detailTextLabel.font = [UIFont systemFontOfSize:14.0];
        [self.contentView addSubview:self.detailTextLabel];
    }
    
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    NSURL *imageUrl = [NSURL URLWithString:self.product.mainUrl];
    [self.imageView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@""]];
    
    self.textLabel.text = self.product.name;
    self.detailTextLabel.text = self.product.price;
}

@end
